package br.com.statizo.financeiro.core.repository.impl;

import javax.persistence.Query;

import snoghert.db.util.PersistenceUtil;
import br.com.statizo.financeiro.domain.entity.impl.ContaCorrente;
import br.com.statizo.financeiro.domain.repo.impl.RepositorioAbstrato;

public class ContaRepository extends RepositorioAbstrato<ContaCorrente>{

	public ContaRepository(PersistenceUtil persistenceUtility) {
		super(persistenceUtility);
	}
	
	public void cleanPadrao(){
		Query query = entityManager.createQuery("update ContaCorrente set padrao = :f where padrao = :t");
		query.setParameter("f", Boolean.FALSE);
		query.setParameter("t", Boolean.TRUE);
		query.executeUpdate();
	}
	
	public ContaCorrente getDefault(){
		try{
			return entityManager.createQuery("from ContaCorrente where padrao = :t", ContaCorrente.class).
					setParameter("t", Boolean.TRUE).getSingleResult();
		}catch(Exception e){
			return null;
		}
	}
}
